<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\GrUser;
use App\Admin\show\StoreDetails;
use App\Admin\show\UserIntegral;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class GrUserIntegralController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new GrUser(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('username');
            $grid->column('head_portrait')->image('',100,100);
            $grid->column('sex');
            $grid->column('real_name');
            $grid->column('tel');
            $grid->column('integral');
            $grid->column('','积分详情')->display('积分详情')->modal(function ($modal) {
                $modal->title('积分详情');
                return UserIntegral::make(['user_id' => $this->id]);
            });
            $grid->disableCreateButton();//新增按钮消失
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->like('username');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new GrUser(), function (Show $show) {
            $show->field('id');
            $show->field('username');
            $show->field('password');
            $show->field('head_portrait');
            $show->field('sex');
            $show->field('payment_code');
            $show->field('real_name');
            $show->field('id_card');
            $show->field('tel');
            $show->field('integral');
            $show->field('balance');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new GrUser(), function (Form $form) {
            $form->display('id');
            $form->text('username');
            $form->text('password');
            $form->text('head_portrait');
            $form->text('sex');
            $form->text('payment_code');
            $form->text('real_name');
            $form->text('id_card');
            $form->text('tel');
            $form->text('integral');
            $form->text('balance');
            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
